<template>
  <div class="wrap">
    <div class="login">
      <h2>积云会员管理系统</h2>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="ruleForm.username"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="ruleForm.password"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    submitForm() {
        this.$refs["ruleForm"].validate(valid=>{
            // console.log(valid);
           if(valid){
               this.$store.dispatch("user",this.ruleForm).then(response=>{
                  //  console.log(response);
                  if(response.data.flag){
                    this.$router.push("/index")
                  }
               })
           }

        })
    },
  },
};
</script>

<style lang='scss' scoped>
.wrap {
  width: 100%;
  height: 100%;
  background: url(http://mengxuegu.com:9999/img/login.b665435f.jpg) no-repeat;
  .login {
    position: absolute;
    width: 350px;
    height: max-content;
    background: rgba(251, 248, 248, 0.6);
    top: 50%;
    left: 50%;
    margin-left: -175px;
    margin-top: -180px;
    padding: 25px;
    border-radius: 15px;
    h2 {
      color: white;
      font-weight: 900;
      margin-left: 130px;
      padding: 20px 0;
    }
  }
}
</style>
